package znbkListXtfx.paperAssemblyRecordInfo;

import android.util.Log;

import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import java.util.List;

import znbkListRdqh.isNeedPaperAssembly.ILoadDateViewAssembly;
import znbkListRdqh.isNeedPaperAssembly.ILoadDatePresenterAssembly;
import znbkListXtfx.fragment.SystemReviewListFragment;

/**
 * Created by Administrator on 2018\4\20 0020.
 */

public class PaperAssemblyRecordPresenter implements ILoadDatePresenterAssembly {

        private ILoadDateViewAssembly view;

        public PaperAssemblyRecordPresenter(ILoadDateViewAssembly view) {
                this.view = (ILoadDateViewAssembly) view;
            }

        @Override
        public void getData() {

            HttpOnNextListener<List<PaperAssemblyRecordResult>> httpOnNextListener = new HttpOnNextListener<List<PaperAssemblyRecordResult>>() {
                @Override
                public void onNext(List<PaperAssemblyRecordResult> paperAssemblyRecordResult) {
                    Log.e("ThisPaperIndex","=aaaaa====="+SystemReviewListFragment.ThisPaperIndex);
                    Log.e("AnotherPaperIndex","=aaaaaa======"+SystemReviewListFragment.AnotherPaperIndex);
                    if(paperAssemblyRecordResult.get(0)!=null||
                            (paperAssemblyRecordResult.get(0).getPaperIndex()==SystemReviewListFragment.ThisPaperIndex&paperAssemblyRecordResult.get(0).getResult().equals("1"))){

                        if(paperAssemblyRecordResult.get(0)!=null){
                            SystemReviewListFragment.AnotherPaperIndex = paperAssemblyRecordResult.get(0).getPaperIndex();
                            SystemReviewListFragment.ThisZsds = paperAssemblyRecordResult.get(0).getZSDInfo().toString();
                            SystemReviewListFragment.ThisFilterItem = paperAssemblyRecordResult.get(0).getFilterItem();
                        }else {
                            SystemReviewListFragment.AnotherPaperIndex = 0;
                            SystemReviewListFragment.ThisZsds = "";
                            SystemReviewListFragment.ThisFilterItem = "";
                        }
                        //需要组卷
//                        ToastUtils.showShort("需要组卷");
                        view.assemblyPaper();
                        SystemReviewListFragment.mTvToolbarTitle.setText("系统复习（组卷中...）");
                    }else{
                        //无需组卷
//                        ToastUtils.showShort("完成组卷");
                        if(paperAssemblyRecordResult.get(0).getResult().equals("0")){
                            SystemReviewListFragment.mTvToolbarTitle.setText("系统复习");
                        }
                    }
                }


                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    view.showNetError();
                }

                @Override
                public void onComplete() {
                    super.onComplete();
                    Log.d("TML","end: "+System.currentTimeMillis());
                }
            };

            PaperAssemblyRecordApi api = new PaperAssemblyRecordApi(httpOnNextListener, (SystemReviewListFragment) view);
            HttpManager httpManager = HttpManager.getInstance();
            httpManager.doHttpDeal(api);
        }

}
